package com.xieyong.mywebsite.mapper;

import com.xieyong.mywebsite.model.entity.Notice;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Mapper
public interface BaseNoticeMapper {

    @Select("SELECT id, title, content, author, create_time from  base_notice where is_deleted = 0 and id = #{id}")
    Notice selectById(int id);

    @Select("SELECT id, title, content, author, create_time from  base_notice where is_deleted = 0")
    List<Notice> selectAll();

    List<Notice> selectByCondition(String title, String content, LocalDateTime startTime, LocalDateTime endTime);

    @Insert("INSERT into base_notice (title, content, author, create_time,update_time) value (#{title},#{content},#{author},#{createTime},#{updateTime}) ")
    void insert(Notice notice);

    @Update("UPDATE base_notice set title = #{title}, content = #{content}, author = #{author}, update_time=#{updateTime} where id = #{id}")
    void update(Notice notice);

    @Update("UPDATE base_notice set is_deleted = 1, deleted_time = #{deletedTime}, deleted_id = #{userId} where id = #{noticeId}")
    void delete(LocalDateTime deletedTime, Integer userId, Integer noticeId);
}
